package com.example.myblog.common;

import com.example.myblog.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSessionTools {
    /**
     * 获取当前登录用户信息
     * */
    public static UserInfo getLoginUser(HttpServletRequest request){
        HttpSession session=request.getSession(false);
        if (session!=null&&session.getAttribute(ApplicationVariable.SESSION_USERINFO_KEY)!=null)
        {
            UserInfo userInfo=(UserInfo) session.getAttribute(ApplicationVariable.SESSION_USERINFO_KEY);
            return userInfo;
        }
        return null;
    }
}
